package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "CheckCodeServlet", value = "/CheckCodeServlet")
public class CheckCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String resultTip="icon/wrong.jpg";
        //获取用户验证码
        String client=request.getParameter("checkcode");
        String checkcode=(String)request.getSession().getAttribute("CHECKCODE");
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        // System.out.println(checkcode+","+client);
        if (client.equals(checkcode)) {
            resultTip="icon/right.jpg";
        }
        PrintWriter writer=response.getWriter();
        writer.write(resultTip);
        writer.flush();
        writer.close();
    }
}
